<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>cylinder</title>
    <!-- <script src="../../node_modules/three/build/three.js"></script>
    <script type="module" src="../../node_modules/three/examples/jsm/controls/OrbitControls.js"></script> -->
    <!-- <script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script> -->
    <script type="importmap">
        {
            "imports": {
                "three": "../../node_modules/three/build/three.module.js"
            }
        }
    </script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            margin: 0;
            overflow: hidden;
        }
    </style>

</head>

<body>

</body>
<script type="module">
    import * as THREE from 'three';

    // import { OrbitControls } from './jsm/controls/OrbitControls.js';
    // import * as THREE from 'three'
    import { OrbitControls } from '../../node_modules/three/examples/jsm/controls/OrbitControls.js'
    //创建柱面与材质
    const scene = new THREE.Scene();


    const geometry = new THREE.CylinderGeometry(50, 50, 100, 20,1);
    const material = new THREE.MeshBasicMaterial({ color: 0x1A79A9 });
    const cylinder = new THREE.Mesh(geometry, material);
    scene.add(cylinder);

    // const material1 = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide, color: 0x000000, wireframe: true, transparent: true, opacity: 0.99 });
    // const mesh1 = new THREE.Mesh(geometry, material1);
    // scene.add(mesh1);

    // const material2 = new THREE.MeshBasicMaterial({ side: THREE.FrontSide, color: 0x006600, transparent: true, opacity: 0.9 });
    // const mesh2 = new THREE.Mesh(geometry, material2);
    // scene.add(mesh2);


    //显示三角化
    const wireframe = new THREE.WireframeGeometry(geometry);

    const line = new THREE.LineSegments(wireframe);
    line.material.depthTest = false;
    line.material.opacity = 0.25;
    line.material.transparent = true;
    scene.add(line);



    //系统坐标系绘制-----------------------------------------
    var axesHelper = new THREE.AxesHelper(300);
    axesHelper.setColors('0xff4400', '0xfffff', '0x222222')
    scene.add(axesHelper);

    //网格线绘制
    var grid = new THREE.GridHelper(600, 20, 0xFF0000, 0x444444);
    grid.material.opacity = 0.4;
    grid.material.transparent = true;
    // grid.rotation.x = Math.PI / 2.0;
    scene.add(grid);
    //--------------------------------------------------------
    const height = window.innerHeight;
    const width = window.innerWidth;

    const camera = new THREE.OrthographicCamera(width / -2, width / 2, height / 2, height / -2, 1, 5000);
    camera.position.set(200, 200, 200);
    camera.lookAt(scene.position); //设置相机方向(指向的场景对象)

    const renderer = new THREE.WebGLRenderer();
    renderer.setSize(width, height);
    renderer.setClearColor(0x444444);

    document.body.appendChild(renderer.domElement); //body元素中插入canvas对象

    //控制
    const controls = new OrbitControls(camera, renderer.domElement);

    function render() {
        renderer.render(scene, camera); //执行渲染操作
        cylinder.rotateY(0.02); //每次绕y轴旋转0.01弧度
        controls.update();
        requestAnimationFrame(render); //请求再次执行渲染函数render
    }
    render();
</script>

</html>